package com.linln.wtp.controller.home;

import com.linln.modules.homerotation.domain.HomeRotation;
import com.linln.modules.homerotation.service.HomeRotationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : pengliang
 * @version V1.0
 * @Project: timo
 * @Package com.linln.wtp.controller.home
 * @Descriptio /**
 * @Project: timo
 * @Package com.linln.wtp.controller.home
 * @Description: TODO
 * @date Date : 2021年01月13日 9:51
 */
@RestController
@RequestMapping("rotation")
public class HomeRotationController {

    @Autowired
    private HomeRotationService homeRotationService;

    @Value("${server.ip}")
    private String ip;

    /**
     * 获取主页轮播图
     * @return
     */
    @GetMapping
    public Map<String, Object> getHomeRotationList() {
        List<HomeRotation> honeRotation = homeRotationService.getHoneRotation(0);
        honeRotation.forEach(item -> {
            item.setHrAddress(ip + item.getHrAddress());
        });
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("data", honeRotation);
        return map;
    }


    /**
     * 获取活动轮播图
     * @return
     */
    @GetMapping("/activity")
    public Map<String, Object> getHomeActivityRotationList() {
        List<HomeRotation> honeRotation = homeRotationService.getHoneRotation(1);
        honeRotation.forEach(item -> {
            item.setHrAddress(ip + item.getHrAddress());
        });
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("data", honeRotation);
        return map;
    }
}
